package example;

class MyThread extends Thread{
    public int count;

    public void add(){
        count++;
    }
    public int getCount(){
        return count;
    }
    @Override
    public void run() {
        for (int i = 0; i < 50000;i++) {
            add();
        }
    }
}
public class Example9 {
    public static int count = 0;

    public static void main(String[] args) {
        MyThread t1 = new MyThread();
        MyThread t2 = new MyThread();
        t1.start();
        t2.start();

        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        System.out.println(t1.getCount());
    }

    public static void main1(String[] args) {

        Thread t1 = new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                count++;
            }
        });

        Thread t2 = new Thread(()-> {
            for (int i = 0; i < 50000; i++) {
                count++;
            }
        });

        t1.start();
        t2.start();
        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        System.out.println("count = "+count);
    }
}
